#include <cstdio>
#include <algorithm>
int x[5555];
using namespace std;
int min(int x,int y)
{
	return x<y?x:y;
}
int main() 
{
	freopen("test.in","r",stdin);
	int n;
	while (scanf("%d",&n)!=EOF) 
	{
//		build(0,n-1,1);
		int sum = 0;
		for (int i=1;i<=n;i++)
		{
			scanf("%d",&x[i]);
			for(int j=i-1;j>=1;j--)
				if(x[i]<x[j])sum++;
		}
		int ret = sum;
		for (int i=1;i<=n;i++) 
		{
			sum+=n-x[i]-x[i]-1;
			ret=min(ret,sum);
		}
		printf("%d\n",ret);
	}
	return 0;
}





